<template>
  <view class="my-userinfo-wrapper">
    <!-- 头部信息 -->
    <view class="top-box">
      <image class="avtor" :src="userinfo.avatarUrl"> </image>
      <view class="nickname">{{ userinfo.nickName }}</view>
    </view>

    <!-- 画板区域 -->
    <view class="panel-list">
      <!-- 第一个面板 -->
      <view class="panel-body">
        <view class="panel-item">
          <text> 8 </text>
          <text> 收藏的店铺 </text>
        </view>
        <view class="panel-item">
          <text> 14 </text>
          <text> 收藏的商品 </text>
        </view>
        <view class="panel-item">
          <text> 45 </text>
          <text> 关注的商品 </text>
        </view>
        <view class="panel-item">
          <text> 124 </text>
          <text> 足迹 </text>
        </view>
      </view>
      <!-- 第二个面板 -->
      <view class="panel-body2">
        <view class="panel-title">我的订单</view>
        <view class="panel-item-wrappr">
          <view class="panel-item">
            <image src="/static/my-icons/icon1.png"> </image>
            <text> 待付款 </text>
          </view>
          <view class="panel-item">
            <image src="/static/my-icons/icon2.png"> </image>
            <text> 待收货 </text>
          </view>
          <view class="panel-item">
            <image src="/static/my-icons/icon3.png"> </image>
            <text> 退款/退货 </text>
          </view>
          <view class="panel-item">
            <image src="/static/my-icons/icon4.png"> </image>
            <text> 全部订单 </text>
          </view>
        </view>
      </view>
      <!-- 第三个面板 -->
      <view class="panel-body3">
        <view class="panel-item">
          <text>收货地址</text>
          <uni-icons type="arrowright" size="15" />
        </view>
        <view class="panel-item">
          <text>联系客服</text>
          <uni-icons type="arrowright" size="15" />
        </view>
        <view class="panel-item" @click="logout">
          <text>退出登录</text>
          <uni-icons type="arrowright" size="15" />
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { mapMutations, mapState } from "vuex";
export default {
  name: "my-userinfo",
  props: {},
  data() {
    return {};
  },
  computed: {
    ...mapState("m_user", ["userinfo"]),
  },
  methods: {
    ...mapMutations("m_user", [
      "updateUserInfo",
      "updateToken",
      "updateAddress",
    ]),

    // 退出登录
    async logout() {
      const [err, succ] = await uni
        .showModal({
          title: "提示",
          content: "确定要退出登录码",
        })
        .catch((err) => err);

      if (succ && succ.confirm) {
        this.updateAddress({});
        this.updateUserInfo({});
        this.updateToken("");
      }
    },
  },
  watch: {},

  // 组件周期函数--监听组件挂载完毕
  mounted() {},
  // 组件周期函数--监听组件数据更新之前
  beforeUpdate() {},
  // 组件周期函数--监听组件数据更新之后
  updated() {},
  // 组件周期函数--监听组件激活(显示)
  activated() {},
  // 组件周期函数--监听组件停用(隐藏)
  deactivated() {},
  // 组件周期函数--监听组件销毁之前
  beforeDestroy() {},
};
</script>

<style scoped lang="scss">
.my-userinfo-wrapper {
  height: 100vh;
  background-color: #f4f4f4;
  // 头部用户信息
  .top-box {
    background-color: #c00000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 400rpx;
    image {
      background-color: darkcyan;
      width: 90px;
      height: 90px;
      display: block;
      border-radius: 100%;
      border: 2px solid #fff;
      box-shadow: 0 1px 5px black;
    }
    .nickname {
      color: #fff;
      margin-top: 5px;
      font-size: 16px;
      font-weight: bold;
    }
  }

  // 面版区域
  .panel-list {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: -20rpx;

    .panel-body {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      width: 90%;
      padding: 0 10px;
      background-color: #fff;
      height: 50px;
      border-radius: 5px;

      .panel-item {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        font-size: 12px;
      }
    }

    .panel-body2 {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      width: 90%;
      padding: 10px;
      background-color: #fff;
      border-radius: 5px;
      margin-top: 20rpx;

      .panel-title {
        font-size: 13px;
      }

      .panel-item-wrappr {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        margin-top: 20rpx;

        .panel-item {
          display: flex;
          flex-direction: column;
          align-items: center;
          padding: 5px;

          image {
            display: block;
            width: 30px;
            height: 30px;
          }

          text {
            margin-top: 2px;
            font-size: 12px;
          }
        }
      }
    }

    .panel-body3 {
      display: flex;
      flex-direction: column;
      width: 90%;
      padding: 0 10px;
      background-color: #fff;
      border-radius: 5px;
      margin-top: 20rpx;

      .panel-item {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 5px 0;
        text {
          font-size: 13px;
        }
      }
    }
  }
}
</style>